﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Csla.Xaml;
using Accounting.Library;
using System.Windows.Data;
using BusinessConfiguration;
using System.Collections;
using System.Collections.Generic;
using Accounting.Library.Utility;

namespace csla4Skeleton.UI.SL.DanhMuc.DM_TaiKhoan
{
    public class DM_TaiKhoan_ListViewModel : ViewModel<DM_TaiKhoanList>
    {
        public event EventHandler ListTaiKhoanChanged;
        public event EventHandler LoadCompleted;

        public DM_TaiKhoan_ListViewModel(string mode)
        {
                BeginRefresh("GetDM_TaiKhoanList", mode);
        }

        public DM_TaiKhoan_ListViewModel(List<string> list)
        {
            BeginRefresh("GetDM_TaiKhoanList", list);
        }

        protected override void OnRefreshed()
        {
            base.OnRefreshed();
            if (Model != null)
            {
                if (ListTaiKhoanChanged != null)
                {
                    ListTaiKhoanChanged(this, new EventArgs());
                }

                if (LoadCompleted != null)
                {
                    LoadCompleted(this, new EventArgs());
                }
            }
        }

        public void filterDKNV(List<string> list)
        {
            BeginRefresh("GetDM_TaiKhoanList", list);    
        }
        
        public void GetDM_TaiKhoan_ListViewModel(string mode)
        {
            BeginRefresh("GetDM_TaiKhoanList", mode);
        }

        public static readonly DependencyProperty SelectedItemProperty =
          DependencyProperty.Register("SelectedItem", typeof(DM_TaiKhoanInfo), typeof(DM_TaiKhoan_ListViewModel), null);
        public DM_TaiKhoanInfo SelectedItem
        {
            get { return (DM_TaiKhoanInfo)GetValue(SelectedItemProperty); }
            set { SetValue(SelectedItemProperty, value); }
        }

        public void DeleteDM_TaiKhoan(object sender, ExecuteEventArgs e)
        {
            if (e.MethodParameter != null)
            {
                //cast parameter
                string parameter = e.MethodParameter.ToString();
                this.IsBusy = true;
                Accounting.Library.DM_TaiKhoan.DeleteDM_TaiKhoan(int.Parse(parameter), (o, ex) =>
                {
                    BeginRefresh("GetDM_TaiKhoanList", BusinessConfiguration.Configuration.GridViewFetchMode);
                });
                this.IsBusy = false;
            }
        }       
    }
}






